package com.huangwei.service.impl;

import com.huangwei.dao.UserDao;
import com.huangwei.model.User;
import com.huangwei.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserDao userDao;
    @Override
    public int addUser(User user) {
        try {
            return userDao.add(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public int deleteUser(int userId) {
        try {
            return userDao.delete(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public int updateUser(User user) {
        try {
            return userDao.update(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public User getOneUserById(int userId) {
        try {
            return userDao.queryOne(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public User getOneUserByPhone(String phone) {
        try {
            return userDao.queryOneByPhone(phone);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public User getOneUserToLogin(String phone, String password) {
        try {
            return userDao.queryOneToLogin(phone, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<User> getAllUsers() {
        try {
            return userDao.queryAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
